<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仓库管理系统</title>
    <link rel="stylesheet" href="/css/bootstrap.css">
    <link rel="stylesheet" href="/css/style.css">
    <script src="/js/bootstrap.bundle.js"></script>
    <style>
        body {
            padding-top: 56px;
        }

        .sidebar {
            height: 100%;
            width: 250px;
            position: fixed;
            top: 56px;
            left: 0;
            background-color: #f8f9fa;
            padding-top: 20px;
        }

        .sidebar a {
            padding: 10px 15px;
            text-align: left;
            display: block;
            color: #000;
            text-decoration: none;
        }

        .sidebar a:hover {
            background-color: #ddd;
            color: black;
        }

        .content {
            margin-left: 250px;
            padding: 20px;
        }

        .hidden {
            display: none;
        }
    </style>
</head>

<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
    <a class="navbar-brand" href="#">仓库管理系统</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
            aria-controls="navbarNav"
            aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ml-auto">
            <li class="nav-item">
                <a class="nav-link" href="#">欢迎您，仓库管理员（ID: <span th:text="${session.name}"></span>）</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="settingsDropdown" role="button"
                   data-bs-toggle="dropdown"
                   aria-haspopup="true" aria-expanded="false">
                    设置
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="settingsDropdown">
                    <div th:if="${session.isTotalAdmin}">
                        <a class="dropdown-item" th:href="@{/order}">进入订单管理</a>
                        <a class="dropdown-item" th:href="@{/user/sysAdmin}">进入系统管理</a>
                        <div class="dropdown-divider"></div>
                    </div>
                    <a class="dropdown-item" th:href="@{/logout}">退出登录</a>
                    <a class="dropdown-item" href="#" onclick="location.reload();">刷新页面</a>
                </div>
            </li>
        </ul>
    </div>
</nav>

<!-- Sidebar -->
<div class="sidebar">
    <a th:href="@{/inventory}">出入库记录</a>
    <a th:href="@{/inventory/record}">原料出入库</a>
    <a th:href="@{/inventory/management}">仓库管理</a>
    <a th:href="@{/inventory/warning}">原料管理</a>
    <a th:href="@{/inventory/supplier}">供应商管理</a>
</div>

<!-- Content -->
<div class="content">
    <h2>仓库管理界面</h2>
    <!-- 原料总量及警戒值 -->
    <div id="alertSection" class="section">
        <h3>原料总量及警戒值</h3>
        <form th:action="@{/inventory/totalMaterial}" th:method="post">
            <div class="form-group">
                <label for="materialName1">原料名</label>
                <input type="text" class="form-control" id="materialName1" name="materialName"
                       placeholder="按原料名查询">
            </div>
            <button type="submit" class="btn btn-primary">查询</button>
        </form>
        <table class="table">
            <thead>
            <tr>
                <th>原料名</th>
                <th>总量</th>
                <th>警戒值</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <!-- 原料总量及警戒值数据 -->
            <tr th:each="totalMaterial:${totalMaterials}">
                <td th:text="${totalMaterial.getMaterialName()}"></td>
                <td th:text="${totalMaterial.getMaterialTotalNumber()}"></td>
                <td th:text="${totalMaterial.getMinimumStock()}"></td>
                <td>
                    <button type="button" class="btn btn-primary"
                            th:attr="onclick='showEditWarningModal(\'' + ${totalMaterial.getMaterialName()} + '\');'">
                        修改警戒值
                    </button>
                </td>
            </tbody>
        </table>
    </div>
</div>
<!--修改警戒值弹窗-->
<div class="modal fade" id="editWarningModal" tabindex="-1" role="dialog" aria-labelledby="editUserModalLabel"
     aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editUserModalLabel">修改警戒值</h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form th:action="@{/inventory/updateMinimumStock}" method="post">
                    <div class="form-group">
                        <label for="updateMaterialName">材料名</label>
                        <input type="text" class="form-control" id="updateMaterialName" name="updateMaterialName"
                               readonly>
                    </div>
                    <div class="form-group">
                        <label for="minimumStock">警戒值</label>
                        <input type="text" class="form-control" id="minimumStock" name="minimumStock" required>
                    </div>
                    <button type="submit" class="btn btn-primary mt-3">确定修改</button>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    function showEditWarningModal(materialName) {
        document.getElementById('updateMaterialName').value = materialName;
        // 使用Bootstrap的API打开模态框
        var modal = new bootstrap.Modal(document.getElementById('editWarningModal'));
        modal.show();
    }
</script>
</body>
</html>